<template>
	<view class="hospital-select">
		<view class="header">
			<text class="title">选择医院</text>
		</view>
		
		<view class="admin-list">
			<view class="section-title">医院列表</view>
			<view 
				class="admin-item" 
				v-for="admin in adminList" 
				:key="admin"
				@click="selectHospital(admin)"
			>
				<view class="admin-info">
					<text class="admin-name">{{ admin }}</text>
					<text class="arrow">></text>
				</view>
			</view>
		</view>
		

	</view>
</template>

<script>
import request from '@/utils/request.js'
import tokenManager from '@/utils/token.js'

export default {
	data() {
		return {
			adminList: []
		}
	},
	
	onLoad() {
		this.loadAdminList()
	},
	
	methods: {
		// 加载管理员列表
		async loadAdminList() {
			// 检查登录状态
			if (!tokenManager.isLoggedIn()) {
				uni.showModal({
					title: '提示',
					content: '请先登录后再查看医院列表',
					showCancel: false,
					confirmText: '去登录',
					success: (res) => {
						if (res.confirm) {
							uni.navigateTo({
								url: '/pages/login/login'
							})
						}
					}
				})
				return
			}

			try {
				const response = await request.request({
					url: '/activity/admin/names',
					method: 'GET'
				})
				
				if (response.code === 200) {
					this.adminList = response.data || []
				} else {
					uni.showToast({
						title: response.message || '获取医院列表失败',
						icon: 'none'
					})
				}
			} catch (error) {
				console.error('获取医院列表失败:', error)
				uni.showToast({
					title: '网络错误',
					icon: 'none'
				})
			}
		},
		
		// 选择医院
		async selectHospital(hospitalName) {
			// 跳转到活动列表页面，并传递医院参数
			uni.navigateTo({
				url: `/pages/activity/list?hospital=${encodeURIComponent(hospitalName)}`
			})
		},
		

	}
}
</script>

<style scoped>
.hospital-select {
	padding: 20rpx;
	background-color: #f5f5f5;
	min-height: 100vh;
}

.header {
	text-align: center;
	margin-bottom: 30rpx;
}

.title {
	font-size: 36rpx;
	font-weight: bold;
	color: #333;
}

.section-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
	margin-bottom: 20rpx;
	padding-left: 20rpx;
}

.admin-list {
	background-color: #fff;
	border-radius: 12rpx;
	padding: 20rpx;
	margin-bottom: 30rpx;
}

.admin-item {
	padding: 20rpx;
	border-bottom: 1rpx solid #eee;
}

.admin-item:last-child {
	border-bottom: none;
}

.admin-info {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.admin-name {
	font-size: 30rpx;
	color: #333;
}

.arrow {
	color: #999;
	font-size: 28rpx;
}


</style>
